package org.scohen.juploadr.app.tags;

import java.io.Serializable;

public class Tag implements Comparable, Serializable {
    private String tag;

    public Tag(String tag) {
        this.tag = tag.replace('"', ' ').trim();
    }

    public String toString() {
        if (tag.indexOf(' ') >= 0) {
            return "\"" + tag + "\"";
        } else {
            return tag;
        }
    }

    public String toDisplayString() {
        return tag;
    }

    public int compareTo(Object o) {
        Tag another = (Tag) o;
        return toDisplayString().compareTo(another.toDisplayString());
    }

    public boolean equals(Object obj) {
        Tag another = (Tag) obj;
        return this == obj || another.toDisplayString().equals(tag);
    }

    @Override
    public int hashCode() {
        return tag.hashCode() + 42;
    }

    public static void main(String[] args) {
        Tag t = new Tag("\"hi there\"");
        System.out.println(t.toDisplayString());
    }

}
